Skip to main content

How to detect if gamepad joystick was pressed by script using Java

In your Java class, do the following:

public class YourClass extends Component {

@Override
public void start() {

}

@Override
public void repeat() {

// Checking if the X and Y axis of the control's left joystick is greater than 0, if any of the axes is greater than 0, it means it has been moved
if (Input.gamePad.getLeftJoystick().length() > 0) {

// showing a message in the terminal if the conditional is true
Console.log("Left joystick detected!");
}

// Checking if the X and Y axis of the control's right joystick is greater than 0, if any of the axes is greater than 0, it means it has been moved
if (Input.gamePad.getRightJoystick().length() > 0) {

// showing a message in the terminal if the conditional is true
Console.log("Right joystick detected!");
}
}
}